import { _decorator, Component, instantiate, Node, Prefab, ScrollView, Size, UITransform, Vec3 } from 'cc';
import { AudioManager } from '../../../common/src/manager/AudioManager';
import { MonoUIPanel } from '../../../../project-base/src/scripts/MonoUIPanel';
import { UIManager } from '../../../framework/ui/uimanager/UIManager';
import { RankItem } from './RankItem';
const { ccclass, property } = _decorator;

@ccclass('RankPanel')
export class RankPanel extends MonoUIPanel {
    @property({ type: Node, displayName: "好友排行榜背景" })
    friendBg: Node;
    
    @property({ type: Node, displayName: "好友选中" })
    friendSelect: Node;
    
    @property({ type: Node, displayName: "好友未选中" })
    friendNoSelect: Node;
    
    @property({ type: Node, displayName: "总榜排行榜背景" })
    allBg: Node;
    
    @property({ type: Node, displayName: "总榜选中" })
    allSelect: Node;
    
    @property({ type: Node, displayName: "总榜未选中" })
    allNoSelect: Node;
    
    @property({ type: Node, displayName: "我的排名放置处" })
    mineLoc: Node;

    @property({ type: ScrollView, displayName: "总榜未选中" })
    scrollView: ScrollView;

    @property ( {type: Prefab, displayName: "列表的预制体"} )
    randItem: Prefab
    skins = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    
    onLoad(): void {
        var offY = 0
        for (var i = 0; i < this.skins.length; i++) {           
            var rankItem = instantiate( this.randItem )
            rankItem.position = new Vec3(0, -90 * i - 45, 0);
            rankItem.getComponent(RankItem).UpdateInfo( this.skins[i] )
            this.scrollView.content.addChild ( rankItem )

            offY = rankItem.position.y - 50
        }

        this.scrollView.content.getComponent(UITransform).contentSize = new Size(575, offY * -1)

        
        var mineRank = instantiate( this.randItem )
        mineRank.getComponent(RankItem).UpdateInfo( 3 )
        mineRank.parent = this.mineLoc
    }
    // --------------------- 按钮事件 --------------------- //
    private onFriendRankClicked() {
        this.friendBg.active = true
        this.friendSelect.active = true
        this.friendNoSelect.active = false
        
        this.allBg.active = false
        this.allSelect.active = false
        this.allNoSelect.active = true
    }

    private onAllRankClicked() {
        this.friendBg.active = false
        this.friendSelect.active = false
        this.friendNoSelect.active = true
        
        this.allBg.active = true
        this.allSelect.active = true
        this.allNoSelect.active = false
    }
    /** 关闭面板. */
    private async onClosePanel() {
        AudioManager.playButton();
        await this.onExitAnimation();
        UIManager.close("rank:res/prefab/RankPanel");

        //gg.systemEvent.emit(EVENT_NAMES.SHOW_START_BUTTONS, true)
    }
}


